import api from './index'

// 班级相关接口
export interface Class {
  id: number
  name: string
  description: string
  teacher_id: number
  teacher_name: string
  max_students: number
  current_students: number
  status: string
  created_at: string
  updated_at: string
}

export interface ClassDetail extends Class {
  students: any[]
}

export interface CreateClassRequest {
  name: string
  description?: string
  max_students?: number
}

export interface UpdateClassRequest {
  name?: string
  description?: string
  max_students?: number
  status?: string
}

export interface AddStudentsRequest {
  student_ids: number[]
}

export const classesApi = {
  // 获取班级列表
  getClasses(): Promise<Class[]> {
    return api.get('/classes/')
  },

  // 获取班级详情
  getClassDetail(classId: number): Promise<ClassDetail> {
    return api.get(`/classes/${classId}`)
  },

  // 创建班级
  createClass(data: CreateClassRequest): Promise<Class> {
    return api.post('/classes/', data)
  },

  // 更新班级
  updateClass(classId: number, data: UpdateClassRequest): Promise<Class> {
    return api.put(`/classes/${classId}`, data)
  },

  // 添加学生到班级
  addStudents(classId: number, data: AddStudentsRequest): Promise<any> {
    return api.post(`/classes/${classId}/students`, data)
  },

  // 从班级移除学生
  removeStudent(classId: number, studentId: number): Promise<any> {
    return api.delete(`/classes/${classId}/students/${studentId}`)
  },

  // 获取班级作业列表
  getClassAssignments(classId: number): Promise<any[]> {
    return api.get(`/classes/${classId}/assignments`)
  },

  // 获取班级统计信息
  getClassStats(classId: number): Promise<any> {
    return api.get(`/classes/${classId}/stats`)
  }
}
